
import 'package:flutter/material.dart';
import 'package:word_range_client/viewModels/WordBookViewModel.dart';

import '../../viewModels/UserViewModel.dart';

class UserData extends StatefulWidget {
  const UserData({super.key});

  @override
  State<UserData> createState() => _UserDataState();
}

class _UserDataState extends State<UserData> {
  String registerDays = "--";
  String reviewedWordCount = "--";
  String masteredWordCount = "--";

  @override
  void initState() {
    super.initState();
    getRegisterDays();
    getReviewedWordCount();
    getMasteredWordCount();
  }

  void getRegisterDays(){
    UserViewModel().getRegisterDays().then((value) {
      if(value.code == 1){
        setState(() {
          registerDays = "${value.data!}天";
        });
      }
    });
  }

  void getReviewedWordCount(){
    WordBookViewModel().getReviewedWordCount().then((value) {
      if(value.code == 1){
        setState(() {
          reviewedWordCount = "${value.data!}";
        });
      }
    });
  }

  void getMasteredWordCount(){
    WordBookViewModel().getMasteredWordCount().then((value) {
      if(value.code == 1){
        setState(() {
          masteredWordCount = "${value.data!}";
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 90,
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            _UserDataItem(title: "已注册",value: registerDays),
            _UserDataItem(title: "已过招",value: reviewedWordCount),
            _UserDataItem(title: "已掌握",value: masteredWordCount),
          ]
      ),
    );
  }
}



class _UserDataItem extends StatelessWidget {
  const _UserDataItem({super.key, required this.title, required this.value});
  final String title;
  final String value;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 105,
      child: Column(
          children: [
            Text(value,style: const TextStyle(
                fontSize: 27,
                fontWeight: FontWeight.w500,
                color: Colors.white
            ),
            ),
            const SizedBox(height: 5,),
            Text(title,style: const TextStyle(
                fontSize: 15,
                fontWeight: FontWeight.w300,
                color: Colors.white
            )
            )
          ]
      ),
    );
  }
}